<?php

include_once("interface.php");

class Show extends Data
{
    public $fn = "/tmp/config.json";
    public $title = "Show Configuration";
    public $module = "show";
    public $data;
    private $module_list = array("net", "dns", "route", "access", "installation");

    public function __construct() {
    }

    //read the data from files and return a complete object
    function readDataFromSystem() {
        foreach($this->module_list as $m) {
            try {
                $o = ModuleFactory::createModule($m);
                $this->data[$m] = $o->readDataFromSystem();
            }
            catch (Exception $e) {
                echo 'Caught exception: ',  $e->getMessage(), "\n";
            }
        }
        return $this->data;
    }

    //write the obj to the file
    function commitDataToSystem($obj) {
        //this a read only module so nothing to do here
        return 0;
    }

    function printModuleHTML() {
$str = <<<END
    <br>
    You can copy the current configuration and save it as a text file for future use or backup purpose.
    <br>
    <br>
    <fieldset class="ui-widget-content">
    <legend><b>Current Configuration</b></legend>
    <pre id="config" class="" style="width: 70%;"></pre>
    </fieldset>

END;
        return $str;
    }

    function printModuleScript() {
$str = <<<END
<script type="text/javascript">
    function writeDataToHTML(data) {
        var jsonstr = JSON.stringify(data, null, "  ");
        $('#config').html(jsonstr);
    }
</script>

END;
        return $str;
    }
}

?>
